package infiniteLoop
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	public class InfiniteLoopMan
	{
		private static var _ins:InfiniteLoopMan;
		public static function get ins():InfiniteLoopMan
		{
			if(!_ins){
				_ins = new InfiniteLoopMan();
			}
			return _ins;
		}
		
		public var mTimer:Timer;
		private var urlArr:Array = [];
		private var curTime:int;
		
		
		public function InfiniteLoopMan()
		{
			mTimer = new Timer(4);
			mTimer.addEventListener(TimerEvent.TIMER, onTimerEvent);
			mTimer.start();
		}
		public function pushPath(path:String):void
		{
			var index:int = path.lastIndexOf(".as");
			if(index == path.length - 3){
				urlArr.push(path);
			}
		}
		private function onTimerEvent(e:TimerEvent):void
		{
			var time:int = new Date().time;
			if(time - curTime < 60){
				if(urlArr.length){
					var str:String = "InfiniteLoopMan-正在转换，还剩余：" + urlArr.length;
					var curUrl:String = urlArr.shift();
					InfiniteLoop.printMsg.text = str + "，\nurl=" + curUrl;
					try{
						new InfiniteLoop().doLoad(curUrl);
					}
					catch(e:*){
						trace("转换出错，路径为：" + curUrl);
					}
				}
				else{
					InfiniteLoop.printMsg.text = "InfiniteLoopMan-转换完成！";
				}
			}
			curTime = time;
		}
		
	}
}